// $(function (){
//     $('#quantity').on('blur',function (){
//         $.ajax({
//             type     : "GET",
//             url      : "cartAutoRefresh?quantity="+this.value,
//             success  : function (data){
//                 console.log(this.value);
//                 //console.log(data.code);
//             }
//         });
//     });
// });

//  成功版本 0109 23：57
var xhr;
var ids = new Array();
function updateCart1(){

    var len = document.getElementsByClassName("quantity").length;
    var arr = new Array();

    var amounts = new Array();
    for(var i=0;i<len;i++){
        arr[i] = document.getElementsByClassName("quantity").item(i);
        ids[i] = arr[i].id;
        amounts[i] = arr[i].value;
        // console.log(arr[i].value);
        // console.log(arr[i].id);
    }

    //console.log(arr);
    xhr=new XMLHttpRequest();
    xhr.onreadystatechange=process;
    xhr.open("GET","cartAutoRefresh?ids="+ids+"&amounts="+amounts,true);
    xhr.send(null);
}
function process(){
    if(xhr.readyState==4){
        if(xhr.status==200){
            var responseText = xhr.responseText;
            //console.log(responseText);
            var array = responseText.split(",");

            var len = document.getElementsByClassName("quantity").length;
            var arr = new Array();
            var quantities = new Array();
            var total=new Array();

            for(var i=0;i<len;i++){
                // arr[i] = document.getElementsByClassName("quantity").item(i);
                quantities[i] = document.getElementsByClassName("quantity");
                total[i] = document.getElementsByClassName(ids[i]);
                console.log(total[i]);
            }

            for(var i=0,j=0;i<len*2;i=i+2,j++){
                quantities[j].innerText=array[i];
                total[j][1].innerText = array[i+1];
                console.log(total[j].innerText);
            }
            var subtotal = document.getElementById("subtotal");

            // quantity.innerText = array[0];
            // total.innerText = array[1];
            subtotal.innerText = array[array.length-1];
        }
    }
}
